{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css"> 
.error {padding-left: 5px !important;}
.table{width:98%;display:table;border-left: 1px dotted #e5e5e5;border-right: 1px dotted #e5e5e5;border-bottom: 1px dotted #e5e5e5;background: rgba(204, 204, 204, 0.09);padding: 0px 10px 10px 10px;}
.table-body{min-height:50px;max-height:410px;overflow-y:auto;overflow-x:hidden;}
.inline-block{display:inline-block;}
.w5{width:5%;}
.w75{width:84%;}
.w19{width:10%;text-align:center;}
.w100{width:100% !important;height: 40px;line-height: 40px;border-bottom: 1px dotted #e5e5e5;}
.add-spec{height: 40px;line-height: 40px;border-bottom:1px dotted #E6E6E6;}
input{vertical-align: initial;}
.table input[type="text"], input[type="password"], input.text, input.password {font: 12px/20px Arial;color: #777;background-color: #FFF;vertical-align: baseline;margin-bottom:0px;}
.set-style dl dt {text-align:right;width: 10%;}
label.line-label{display:inline-block;margin-right:10px;font-weight:normal;}


</style>
{/block}
{block name="main"}
<div class="space-10"></div>
<div class="set-style">
	<dl>
		<dt><span class="color-red">*</span>规格名称：</dt>
		<dd>
			<input id="spec_name" type="text" placeholder="请输入规格名称" class="input-common"/>
			<span class="error">请输入规格名称</span>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">&nbsp;</span>规格排序：</dt>
		<dd>
			<input id="sort" type="number" value="0" onkeyup='this.value=this.value.replace(/\D/gi,"")' class="input-common harf"/>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">&nbsp;</span>是否启用：</dt>
		<dd>
			<input id="is_visible" type="checkbox" class="checkbox" checked="checked" />
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">&nbsp;</span>是否筛选：</dt>
		<dd>
			<input id="is_screen" type="checkbox" class="checkbox" checked="checked" />
		</dd>
	</dl>

	<dl>
		<dt><span class="color-red">&nbsp;</span>展示方式：</dt>
		<dd>
			<label class="radio inline">
				<i class="radio-common selected">
					<input type="radio" name="show_type" id="show_type1" value="1" checked="checked" onchange="change_show_type(1)">
				</i>
				文字
			</label>
			<label class="radio inline">
				<i class="radio-common">
					<input type="radio" name="show_type" id="show_type2" value="2" onchange="change_show_type(2)">
				</i>
				颜色
			</label>
			<label class="radio inline">
				<i class="radio-common">
					<input type="radio" name="show_type" id="show_type3" value="3" onchange="change_show_type(3)">
				</i>
				图片
			</label>
		</dd>
	</dl>
	
	<dl>
		<dt><span class="color-red">*</span>规格值：</dt>
		<dd>
			<textarea rows="" cols="" id="spec_value" class="textarea-common"></textarea>
			<p class="hint">一行为一个规格项，多个规格项用换行输入</p>
		</dd>
	</dl>
	
	<dl>
		<dt>规格说明：</dt>
		<dd>
			<textarea class="textarea-common" placeholder="请输入规格说明" id="spec_des"></textarea>
		</dd>
	</dl>	
	
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="addGoodsSpec();">保存</button>
			<button class="btn-common-cancle btn-big" onclick="window.location.href = window.history.go(-1);">返回</button>
		</dd>
	</dl>
	
</div>
<script>

var flag = false;//防止重复提交

function addGoodsSpec() {
	var spec_name = trim($("#spec_name").val());
	var sort = $("#sort").val();
	var show_type = $("input[name='show_type']:checked").val();
	var spec_des = $('#spec_des').val();
	if ($("#is_visible").prop("checked")) {
		var is_visible = 1;
	} else {
		var is_visible = 0;
	}
	if ($("#is_screen").prop("checked")) {
		var is_screen = 1;
	} else {
		var is_screen = 0;
	}
	
	var spec_value_str = $('#spec_value').val();
	var reg = new RegExp("\n","g");//g,表示全部替换。
	spec_value_str = spec_value_str.replace(reg, ",");
	
	if(spec_name == ''){
		$("#spec_name").focus();
		showTip("规格名称不能为空",'warning');
		return false;
	}
	if(spec_value_str == ''){
		$('#spec_value').focus();
		showTip("规格值不能为空！",'warning');
		return false;
	}
	if(flag){
		return;
	}
	flag = true;
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/addgoodsspec')}",
		data : {
			'spec_name' : spec_name,
			'sort' : sort,
			'is_visible' : is_visible,
			'show_type' : show_type,
			'spec_value_str' : spec_value_str,
			'is_screen':is_screen,
			'spec_des' : spec_des
		},
		success : function(data) {
			if (data["code"] > 0) {
				showTip("添加成功","success");
				location.href = "{:__URL('ADMIN_MAIN/goods/goodsspeclist')}";
			} else {
				showTip("添加失败","error");
				flag = false;
			}
		}
	});
}
//改变展示方式
function change_show_type(type){
	if(type==2){
		$("input[name='spec_value']").after('&nbsp;<input type="color" style="width:60px;margin-top:5px;" name="spec_value_data" class="input-common-color" />');
	}else{
		$("input[name='spec_value']").next("input[type='color']").remove();
	}
}
</script>
{/block}